package com.dd.cloud.user.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.cloud.common.vo.PageVo;
import com.dd.cloud.user.entity.admin.ResourceSet;
import com.dd.cloud.user.entity.menu.BannerImg;
import com.dd.cloud.user.req.admin.AddOrUpdateResourceSetReq;
import com.dd.cloud.user.req.admin.GetSourcePageReq;
import com.dd.cloud.user.req.menu.*;
import com.dd.cloud.user.res.admin.source.BannerImgSystemPageRes;
import com.dd.cloud.user.res.menu.ClientMenuPageRes;
import com.dd.cloud.user.service.admin.IResourceSetService;
import com.dd.cloud.user.service.menu.IBannerImgService;
import com.dd.cloud.user.service.menu.IClientMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Description: 管理员基础数据设置controller
 * @Author: czg
 * @Date: 2023/6/9 15:03
 * @Version: 1.0.0
 */
@RestController
@RequestMapping("/admin")
@Validated
public class AdminResourceController {
    @Autowired
    private IResourceSetService resourceSetService;
    @Autowired
    private IClientMenuService clientMenuService;
    @Autowired
    private IBannerImgService bannerImgService;

    /**
     * 添加或修改基础设置
     *
     * @param req 参数
     * @return
     */
    @PostMapping("/resource/addOrUpdate")
    public ResponseEntity<Void> resourceAddOrUpdate(@Valid @RequestBody AddOrUpdateResourceSetReq req) {
        resourceSetService.resourceAddOrUpdate(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改基础设置状态
     *
     * @param id     id
     * @param status 状态 1正常 3禁用 -1删除
     * @return
     */
    @PostMapping("/resource/update/status")
    public ResponseEntity<Void> resourceUpdateStatus(@NotNull(message = "id不能为空") Integer id, @NotNull(message = "状态不能为空") Integer status) {
        resourceSetService.resourceUpdate(id, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 分页查询基础设置
     *
     * @param req 参数
     * @return
     */
    @GetMapping("/resource/page")
    public ResponseEntity<Page<ResourceSet>> resourcePage(@Valid GetSourcePageReq req) {
        Page<ResourceSet> page = resourceSetService.resourcePage(req);
        return ResponseEntity.ok(page);
    }

    /**
     * 分页查询基础设置
     *
     * @param type 参数 类型 1 处方审核知情协议 2处方用工协议  3服务协议 4隐私协议
     * @return
     */
    @GetMapping("/resource/get/type")
    public ResponseEntity<ResourceSet> resourcePage(Integer type) {
        ResourceSet res = resourceSetService.resourceGetByType(type);
        return ResponseEntity.ok(res);
    }

    /**
     * 获取统一配置的菜单
     *
     * @param req
     */
    @GetMapping("/menu/page")
    public ResponseEntity<Page<ClientMenuPageRes>> getMenuPagePage(@Valid ClientMenuPageReq req) {
        Page<ClientMenuPageRes> res = clientMenuService.getClientMenuPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 添加统一配置的菜单
     *
     * @param req
     */
    @PostMapping("/menu/add")
    public ResponseEntity<Void> addMenuPage(@Valid CreatClientMenuReq req) {
        clientMenuService.addWholeClientMenu(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改统一配置的菜单
     *
     * @param req
     */
    @PostMapping("/menu/update")
    public ResponseEntity<Void> updateMenu(@Valid UpdateClientMenuReq req) {
        clientMenuService.updateWholeClientMenu(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改统一配置的菜单
     *
     * @param id
     */
    @PostMapping("/menu/update/status")
    public ResponseEntity<Void> updateMenuStatus(@NotNull(message = "id不能为空") Integer id, @NotNull(message = "状态不能为空") Integer status) {
        clientMenuService.updateWholeClientMenuStatus(id, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 获取轮播图-医生端
     *
     * @param type
     */
    @GetMapping("/banner/list")
    public ResponseEntity<List<BannerImg>> getBannerImgList(Integer type) {
        List<BannerImg> res = bannerImgService.getBannerImgList(type);
        return ResponseEntity.ok(res);
    }

    /**
     * 获取轮播图-运营端分页
     *
     * @param req
     */
    @GetMapping("/banner/page")
    public ResponseEntity<PageVo<BannerImgSystemPageRes>> getBannerImgPage(@Valid GetBannerImgPageReq req) {
        PageVo<BannerImgSystemPageRes> res = bannerImgService.getBannerImgPage(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 添加轮播图
     *
     * @param req
     */
    @PostMapping("/banner/add")
    public ResponseEntity<String> addBannerImg(@RequestBody @Valid AddBannerImgReq req) {
        String res = bannerImgService.addBannerImg(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 修改轮播图
     *
     * @param req
     */
    @PostMapping("/banner/update")
    public ResponseEntity<String> updateBannerImg(@RequestBody @Valid UpdateBannerImgReq req) {
        String res = bannerImgService.updateBannerImg(req);
        return ResponseEntity.ok(res);
    }

    /**
     * 修改轮播图状态
     *
     * @param id
     */
    @PostMapping("/banner/update/status")
    public ResponseEntity<Void> updateBannerImgStatus(@NotNull(message = "id不能为空") Integer id, @NotNull(message = "状态不能为空") Integer status) {
        bannerImgService.updateBannerImgStatus(id, status);
        return ResponseEntity.ok().build();
    }
}
